<template>
	<view class="content">
		<view class="content">
			<!-- <cu-custom bgColor="bg-gradual-blue">
					<block slot="content">个人技能</block>
				</cu-custom> -->
			<swiper class="swiper-box" :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
				:duration="duration">
				<swiper-item v-for="(item, index) in info" :key="index">
					<view :class="item.colorClass" class="swiper-item">
						<image class="image" :src="item.url" mode="aspectFill" />
					</view>
				</swiper-item>
			</swiper>
		</view>
		<uni-notice-bar scrollable single text="[通知] 第一届趣味运动会将在本周五举行,请各位同学积极参与."></uni-notice-bar>
		<view class="item">
			<uni-list>
				<uni-list-item title="代办事项" showArrow thumb="/static/闹钟.png" thumb-size="lg" rightText="2条" />
			</uni-list>
		</view>

		<view class="body">
			<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text"
				activeColor="#d91539"></uni-segmented-control>
			<view class="content">
				<view v-show="current === 0">

					<!-- 列表为空时 -->
					<view v-if="allitems.length === 0" class="listNone">
						<image src="../../static/空白页面插图.png" mode=""></image>
						<view class="goIn">暂无数据</view>
					</view>

					<!-- 主页全部卡片列表 -->
					<view class="" v-else v-for="item in allitems" :key="item.id">
						<uni-card :title="item.cname + '班'" :sub-title="item.create_time" :thumbnail="item.path"
							:extra="item.state === '0' ? '进行中' : '已结束'">
							<view v-show=" item.type==='1'">作业详情</view>
							<view v-show=" item.type==='2'">通知：因五一假期冲突，
								11周《大学生就业指导》周一的34节课调至11周周五上午34节课。教室不变A3W401，请知悉。
							</view>
						</uni-card>
					</view>

				</view>

				<view v-show=" current===1">
					<!-- 列表为空时 -->
					<view v-if="work.length === 0" class="listNone">
						<image src="../../static/空白页面插图.png" mode=""></image>
						<view class="goIn">暂无数据</view>
					</view>
					<!-- 作业列表 -->
					<view class="work" v-else>
						<uni-card v-for="item in work" :title="item.homeworkTaskName" :sub-title="item.startTime"
							:thumbnail="item.path"
							:extra="new Date().getTime() > new Date(item.stopTime) ? '进行中' : '已结束'">
							<view>

								<view style="font-size: 16px;">
									作业内容：{{item.content}}
								</view>
								<view style="text-align: right;" @click="homework(item.taskId)">
									<button type="default" size="mini">作业详情</button>
								</view>
							</view>
						</uni-card>
					</view>

				</view>

				<view v-show="current === 2">
					<!-- 列表为空时 -->
					<view v-if="report.length === 0" class="listNone">
						<image src="../../static/空白页面插图.png" mode=""></image>
						<view class="goIn">暂无数据</view>
					</view>
					<!-- 通知列表 -->
					<view class="report" v-else>
						<uni-card v-for="reportItem in report" :key="reportItem.id" :title="reportItem.bname"
							:sub-title="reportItem.create_time" :thumbnail="reportItem.path" extra="lijie老师">
							<view :style="">
								通知：{{reportItem.content}}
							</view>
						</uni-card>
					</view>

				</view>


			</view>
		</view>
		<image @click="loadData" class="refresh" src="../../static/jqr.png" mode="aspectFit"></image>
		<uni-popup ref="popup" type="center">
			<view class="content">
				<image src="../../static/A6BC21085EDEAFD3F16C91C04A220C36.png" mode=""></image>
				<view class="grade">
					9分
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import server from "@/util/http.js"
	export default {
		data() {
			return {
				allitems: [],
				report: [],
				work: [],
				notice: [],
				items: ['我的发布', '作业', '通知'],
				current: 0,
				notice: {},
				speed: 50,
				indicatorDots: true,
				autoplay: true,
				interval: 2000, //切换的间隔时间
				duration: 500, //滑动动画时长
				info: [{
						colorClass: 'uni-bg-red',
						url: 'https://iflyssedata.oss-cn-shanghai.aliyuncs.com/images/20220504111924.png',
						content: '内容 A'
					},
					{
						colorClass: 'uni-bg-green',
						url: 'https://iflyssedata.oss-cn-shanghai.aliyuncs.com/images/20220402034252.png',
						content: '内容 B'
					},
					{
						colorClass: 'uni-bg-blue',
						url: 'https://iflyssedata.oss-cn-shanghai.aliyuncs.com/images/20220503032441.png',
						content: '内容 C'
					}
				],

			}
		},
		onLoad() {
			this.requestWork();
			this.requestReport();
		},
		onPullDownRefresh() {
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 500);
			this.requestWork();
			this.requestReport();
		},
		methods: {
			//获取作业
			requestWork() {
				try {
					const value = uni.getStorageSync('data');
					if (value) {
						let id = value.id;
						server({
							url: 'http://101.43.227.220:3004/homework/list?sid=' + id,
							method: 'post',
							success: res => {
								let data = res.data;
								let m = data.map(value => {
									value.path = '/static/作业.png';
									return value
								});
								this.work = m;

							}
						})
					}
				} catch (e) {
					// error
				}

			},
			//获取通知
			requestReport() {
				server({
					url: 'http://127.0.0.1:4523/mock/906666/report',
					method: 'get',
					success: res => {
						let data = res.data;
						let m = data.map(value => {
							value.path = '/static/通知.png';
							return value
						})
						this.report = m;
					},
					fail: e => {
						console.log(e);
					}
				})
			},
			homework(taskId) {
				uni.navigateTo({
					url: '../homeworkDetail/homeworkDetail?taskId=' + taskId
				})

			},
			loadData() {
				uni.navigateTo({
					url: '../jqr/jqr'
				})
			},
			//点击 进入 详情界面
			signDetail() {
				uni.navigateTo({
					//带 id
					url: '../signDetail/signDetail'
				})
			},
			onClickItem(e) {
				if (this.current != e.currentIndex) {
					this.current = e.currentIndex;
				}
			}
		}
	}
</script>

<style scoped>
	page {
		margin-bottom: 70px;
	}

	.header-item {
		margin-top: 0px;
	}

	.uni-list-item {
		height: 100rpx;

	}

	.notice {
		position: absolute;
		width: 100%;
		top: 210px;
		transform: translateY(-100%);
		z-index: 10;
		opacity: 0.8;
	}

	>>>.uni-list-item__content-title {
		font-size: 34rpx;
	}

	.item {
		margin-top: 20rpx;
	}

	>>>.uni-list-item__extra-text {
		color: red;
		font-size: 30rpx;
	}

	.body {
		margin-top: 30rpx;
	}

	>>>.uni-card .uni-card__header .uni-card__header-extra .uni-card__header-extra-text {
		font-size: 28rpx;
		color: black;
	}

	>>>.uni-list--lg {
		height: 68rpx;
		width: 68rpx;
	}

	>>>.segmented-control .segmented-control__text {
		font-weight: 600;
		font-size: 32rpx;
	}

	.listNone {
		text-align: center;
		margin-top: 70px;
	}

	.listNone image {
		width: 200rpx;
		height: 200rpx;
	}

	.goIn {
		margin-top: 20rpx;
		font-size: 34rpx;
		font-weight: 500;
		font-family: 'Courier New', Courier, monospace;
	}

	.swiper-box {
		width: 100%;
		height: 200px;
	}

	.image {
		width: 100%;
		height: 200px;
	}

	.refresh {
		width: 150upx;
		height: 150upx;
		position: fixed;
		right: 20upx;
		bottom: 200upx;
	}
</style>
